import { Injectable } from '@nestjs/common';
import { JwtService, JwtSignOptions, JwtVerifyOptions } from '@nestjs/jwt';

@Injectable()
export class JwtVerifyService {
    constructor(private jwtService:JwtService) {
        
    }

    sign(payload: Buffer | object, options?: JwtSignOptions) : string{ //生成token
        let token = this.jwtService.sign(payload, options)
        
        return token
    }

    verify(token: string, options?: JwtVerifyOptions) : any{ //验证token
        try {
            let result = this.jwtService.verify(token, options)
            return result
        } catch (error) {
            
        }
        return null
    }
}
